﻿Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols

<WebService(Namespace:="http://www.resamu.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class pj
    Inherits System.Web.Services.WebService

    <WebMethod()> _
    Public Function NewPJ(ByVal idresamu As String, ByVal idteam As String, ByVal idpers As String, ByVal pwd As String, _
    ByVal pjresaid As String, ByVal type As String, ByVal pj As Byte(), _
    ByVal patref As String, ByVal itvref As String, ByVal disc As Boolean) As String
        Dim securite As New ResaSecurite.user
        securite.Url = Application("ResaSecurite")
        securite.Timeout = 60000
        Dim identification As String()
        Dim resalog As New ResaSurvey.logsurvey
        resalog.Timeout = 60000
        resalog.Url = Application("ResaSurvey")
        Dim message As String
        Try
            identification = securite.Identification(idresamu, pwd, idpers).Split("/")
            If identification(0) = "IDOK" Then
                Dim dbPJ As New DataSetPJTableAdapters.listpjTableAdapter
                Select Case disc
                    Case False
                        dbPJ.Insert(pjresaid, patref, itvref, type, "", "non", pj, idresamu, idteam, Now())
                    Case True
                        dbPJ.Insert(pjresaid, patref, itvref, type, "", "oui", pj, idresamu, idteam, Now())
                        Dim fs As New System.IO.FileStream(Server.MapPath("") + "/PJ/" + pjresaid + "." + type, IO.FileMode.Create)
                        fs.Write(pj, 0, pj.Length)
                        fs.Close()
                End Select
                message = "NEWPJOK"
            Else
                message = "ERROR/INTRUSION"
            End If
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        Try
            resalog.NewLog(idresamu, idteam, idpers, "NEWPJ", message)
        Catch ex As Exception

        End Try
        Return message
    End Function
    <WebMethod()> _
    Public Function GetPJ(ByVal idresamu As String, ByVal pwd As String, ByVal idteam As String, _
    ByVal idpers As String, ByVal idpj As String) As Byte()
        Dim securite As New ResaSecurite.user
        securite.Timeout = -1
        securite.Url = Application("ResaSecurite")
        Dim resalog As New ResaSurvey.logsurvey
        resalog.Timeout = -1
        resalog.Url = Application("ResaSurvey")
        Dim identification As String()
        Dim pj As Byte()
        identification = securite.Identification(idresamu, pwd, idpers).Split("/")
        If identification(0) = "IDOK" Then
            Dim dbpj As New DataSetPJTableAdapters.listpjTableAdapter
            Dim pjdata As New DataSetPJ.listpjDataTable
            pjdata = dbpj.GetDataByPJId(idpj)
            pj = pjdata(0).pjvalue
        End If
        Return pj
    End Function
    <WebMethod()> _
    Public Function Test(ByVal idresamu As String, ByVal pwd As String, ByVal idpers As String) As String
        Dim securite As New ResaSecurite.user
        securite.Timeout = 60000
        securite.Url = Application("ResaSecurite")
        Dim resalog As New ResaSurvey.logsurvey
        resalog.Timeout = 60000
        resalog.Url = Application("ResaSurvey")
        Dim message As String
        Try
            message = securite.Identification(idresamu, pwd, idpers)
        Catch ex As Exception
            message = "ERROR/" + ex.Message
        End Try
        Try
            resalog.NewLog(idresamu, "WSPJ", "WSPJ", "TESTPJ", message)
        Catch ex As Exception

        End Try
        Return message
    End Function

End Class
